*****************
* Preliminaries *
*****************

* packages
*ssc install listtab,replace
*ssc install boottest, replace
*ssc install estout, replace
*ssc install reghdfe, replace
*ssc install ftools, replace
*ssc install mylabels, replace
*ssc install coefplot, replace

* grc1leg installation:
*net from http://www.stata.com
*net cd users
*net cd vwiggins
*net install grc1leg

*****************
* preliminaries *
*****************

* filepaths
* --------
set more off
set seed 123

* set your working directory as the location containing the replication folder
capture cd ""

global dopath = "do"
global clean = "data"
global output "output"

* settings and graphics
clear
eststo clear
set scheme lean2 
set more off

* --------- *
* Cleaning  *
* --------- *

* IPUMS international terms of use do not permit the redistribution of microdata.  The .do file below takes a .dat file from the IPUMS international website (international.ipums.org) for the 1994 Moroccan population census, and creates the standardized variables and subsets of the data necessary to reproduce all of the figures and tables used in the paper and appendix.  Please note that without this .dat file and the appropriate variables NONE of the code below will run. To facilitate replication, the data folder includes a screenshot of the variables that need to be downloaded as a .dat file. If any aspect of this code or process is unclear please contact me via email.

do "${dopath}/clean.do"

* --------- *
* Main Text *
* --------- *

* Figure1: Timeline created in Latex with 

* FIGURE2: Age Heaping: Registered and Unregistered
do "${dopath}/Figure2.do"

* FIGURE3: Age Heaping: Reported Months of Birth
do "${dopath}/Figure3.do"

* FIGURE4: Age Heaping: MoB vs. No MoB
do "${dopath}/Figure4.do"

* FIGURE5: Age Heaping: Registration and Literacy Status
do "${dopath}/Figure5.do"

* Descriptive Table 1
* -----------------
do "${dopath}/Table1.do"

* FIGURE6: Event Study
do "${dopath}/Figure6.do"

* Results Table 2
* -----------------
do "${dopath}/Table2.do"

* Results Table 3
* -----------------
do "${dopath}/Table3.do"

* Falsification Test Table 4
* -----------------
do "${dopath}/Table4.do"

* Figure 7 was created in QGIS. Files available upon request

* Mechanisms Test Table 5
* -----------------
do "${dopath}/Table5.do"

* Mechanisms Test Table 6
* -----------------
do "${dopath}/Table6.do"


* -------- *
* Appendix *
* -------- *

* Confounding Table A1
* -----------------
do "${dopath}/TableA1.do"

* Placebo Test Table A2
* -----------------
do "${dopath}/TableA2.do"

* Placebo Test Table A3
* -----------------
do "${dopath}/TableA3.do"

* Placebo Test Table A4
* -----------------
do "${dopath}/TableA4.do"

* Placebo Test Table A5
* -----------------
do "${dopath}/TableA5.do"

* FIGURE3A: Sensitivity Analysis, 1945-1955
do "${dopath}/FIGURE3A.do"

* FIGURE4A: Event Study, 1945-1962
do "${dopath}/FIGURE4A.do"

* FIGURE5A: Sensitivity Analysis, 1945-1962
do "${dopath}/FIGURE5A.do"

* FIGURE6A: Age Heaping Pre / Post, 1962
do "${dopath}/FIGURE6A.do"

* FIGURE7A: Age Heaping MoB vs. No MoB, 1962
do "${dopath}/FIGURE7A.do"

* Full Model: TableA6
* -----------------
do "${dopath}/TableA6.do"

* Full Model: TableA7
* -----------------
do "${dopath}/TableA7.do"

* Full Model: TableA8
* -----------------
do "${dopath}/TableA8.do"

* Full Model: TableA9
* -----------------
do "${dopath}/TableA9.do"

* Full Model: TableA10
* -----------------
do "${dopath}/TableA10.do"

* Alt. Subset, Dropping Casablanca: TableA11
* -----------------
do "${dopath}/TableA11.do"

* Alt. Subset, Dropping Migrants, 1945-1952: TableA12
* -----------------
do "${dopath}/TableA12.do"

* Alt. Subset, Dropping Migrants, 1945-1962: TableA13
* -----------------
do "${dopath}/TableA13.do"

* FIGURE8A: Alternate Subsets, Coefficient Plot
do "${dopath}/FIGURE8A.do"

* FIGURE9A: Alternate Specification without Interaction of controls, Coefficient Plot
do "${dopath}/FIGURE9A.do"

* Alt. Dichotomization, 1945-1955: TableA14
* -----------------
do "${dopath}/TableA14.do"

* Alt. Dichotomization, 1945-1962: TableA15
* -----------------
do "${dopath}/TableA15.do"

* Figure10A, is a map of provinces from the IPUMS Level 2 dataset, it was constructed in QGIS

* FIGURE11A: Alternate Dichotomization, Event Study
do "${dopath}/FIGURE11A.do"

* FIGURE12A: Alternate Dichotomization, Sensitivity Analysis
do "${dopath}/FIGURE12A.do"

* FIGURE13A: Alternate Dichotomization, Coefficient Plot
do "${dopath}/FIGURE13A.do"

* Alt. Outcome, Compulsory Schooling: TableA16
* -----------------
do "${dopath}/TableA16.do"

* FIGURE14A: This image comes from the book cited in the appendix

* Mechanism Test, European Farms, Registration: TableA17
* -----------------
do "${dopath}/TableA17.do"

* Mechanism Test, European Farms, Formal Schooling: TableA18
* -----------------
do "${dopath}/TableA18.do"

* Mechanism Test, European Farms, Formal Schooling, Years: TableA19
* -----------------
do "${dopath}/TableA19.do"

* Mechanism Test, European Farms, Literacy: TableA20
* -----------------
do "${dopath}/TableA20.do"

* Descriptive Statistics, Population and School Censuses, Table A21
* -----------------
do "${dopath}/TableA21.do"

* Mechanism Test, Full Model, Registration and Enrollment: TableA22
* -----------------
do "${dopath}/TableA22.do"

* Mechanism Test, Full Model, Registration and School Infrastructure: TableA23
* -----------------
do "${dopath}/TableA23.do"
